import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;


public class KmerCounter {



	public static void main(String[] args) {
		
		
		ArrayList<String> result = new ArrayList<String>();

		try {
			// file path
			String filePath = "c:\\data.txt";
			// read content file to string
			String data = KmerCounter.readFile(filePath).trim();
			// k mer length
			int k = Integer.valueOf(args[0]);
			// iterate
 			for (int i=0;i<data.length() - k;i++) {
 				
 				//System.out.println("i:" + i);
 				
 				//get kmer
 				String kmer = data.substring(i, i+k);
 				int kcount = 0;
 				// find kmer
 				for (int j=i+1;j<data.length() - k;j++) { 		
 					
 					//System.out.println("j:" + j);
 					
 					String jmer = data.substring(j, j+k);
 					if (jmer.equals(kmer)) {
 						kcount++;
 					} 					
 				}
 				
 				if (kcount > 6) { 
 					//kcount++;
 					//System.out.println(kcount + " - " + kmer);
 					
 					result.add(new String(kcount + " - " + kmer));
 				}
 				
 			}
			
 			
 			Collections.sort(result);
 			
 			for (String s : result) { 				
 				if (s.startsWith("8"))  {				
 					System.out.print(s.substring(3, s.length()).trim() + " ");
 				}
 			}
 			

		} catch (Exception e) {
			System.out.println("ERROR:" + e);}

	}



	public static String readFile( String file ) throws IOException {
		BufferedReader reader = new BufferedReader( new FileReader (file));
		String         line = null;
		StringBuilder  stringBuilder = new StringBuilder();
		String         ls = System.getProperty("line.separator");

		while( ( line = reader.readLine() ) != null ) {
			stringBuilder.append( line );
			//stringBuilder.append( ls );
		}

		return stringBuilder.toString();
	}



}
